unit Thrad_ClarTabl;

interface

uses
  Classes,SysUtils,Class_KzThrad,Uni,UniConfig,UniConnct;

type
  TThradClarTabl = class(TKzThrad)
  private
    FListTabl:TStringList;//*  
  public
    FRealCnfg:TUniConfig; //&
  protected
    procedure Execute; override;
  public
    destructor Destroy; override;
  end;

implementation
uses
  ActiveX;


destructor TThradClarTabl.Destroy;
begin
  if FListTabl<>nil then FreeAndNil(FListTabl);
  inherited;
end;

procedure TThradClarTabl.Execute;
var
  I:Integer;
  SQLA:string;
  TMPA:string;
  UniConnct:TUniConnection;
begin
  try
    UniConnct:=UniConnctEx.GetConnection(FRealCnfg);
    try
      UniConnct.StartTransaction;
      //-<
      SQLA:='SELECT * FROM USER_TABLES ORDER BY TABLE_NAME';
      if FListTabl=nil then
      begin
        FListTabl:=TStringList.Create;
      end;
      UniConnctEx.GetDataSet(SQLA,['TABLE_NAME'],UniConnct,FListTabl);

      if (FListTabl=nil) or (FListTabl.Count=0) then Exit;

      GetMaxProgress(FListTabl.Count);
      for I:=0 to FListTabl.Count-1 do
      begin
        GetOneProgress(I+1);

        TMPA:=UpperCase(Trim(FListTabl.Strings[I]));
        SQLA:=Format('DROP TABLE %S',[TMPA]);
        GetTxtProgress(Format('DELETE %S .....',[TMPA]));
        UniConnctEx.ExecuteSQL(SQLA,UniConnct);
      end;

      GetEndProgrees;        
      //->
      UniConnct.Commit;
    except
      on E:Exception do
      begin
        UniConnct.Rollback;
        raise Exception.Create(E.Message);
      end;
    end;
  finally
    FreeAndNil(UniConnct);
  end;
end;

end.
